#include <cstdio>
struct Rational {
	int quotient;
	int divisor;
private:	
	static int NOD(int a,int b) {
		while(a!=0 && b!=0) {
			if(a>=b) a=a%b;
			else b=b%a;
		}
	return a+b; // Одно - ноль
	}
	static int NOK(int a, int b) {
		return a*b/NOD(a,b);
	}
	inline void fractionCancellation() {
		int a=quotient<0?-quotient:quotient;
		int b=divisor<0?-divisor:divisor;
		int c=NOD(a,b);
		quotient/=c;
		divisor/=c;
	}
	inline int checkDivisor() const{
		if (divisor==0) {
			printf("Error: divisor is 0!\n");
			return -1;
		}
		return 0;
	}
public:	
	Rational() : quotient(0), divisor(1) {}
	Rational(int i) : quotient(i), divisor(1) {}
	Rational(int a, int b) {
		quotient=a;
		divisor=b;
		if (checkDivisor()||a==0) return;
		fractionCancellation();
	}
	Rational(const Rational &r) : quotient(r.quotient), divisor(r.divisor) {
		checkDivisor();	
	}
	Rational& operator=(const Rational &r) {
		quotient=r.quotient;
		divisor=r.divisor;
		return *this;
	}
	Rational& operator+=(const Rational &r) {
		if (checkDivisor()||r.checkDivisor()) return *this;
		quotient=quotient*r.divisor+r.quotient*divisor;
		divisor*=r.divisor;
		fractionCancellation();
		return *this;
	}
	Rational& operator-=(const Rational &r) {
		if (checkDivisor()||r.checkDivisor()) return *this;
		quotient=quotient*r.divisor-r.quotient*divisor;
		divisor*=r.divisor;
		fractionCancellation();
		return *this;
	}
	Rational& operator*=(const Rational &r) {
		if (checkDivisor()||r.checkDivisor()) return *this;
		quotient*=r.quotient;
		divisor*=r.divisor;
		fractionCancellation();
		return *this;
	}
	Rational& operator/=(const Rational &r) {
		Rational tmp(*this);
		if (checkDivisor()||r.checkDivisor()) return *this;
		if (r.quotient==0) {
			printf("Error: Dividing by 0!\n");
			return *this;
		}
		tmp.quotient*=r.divisor;
		tmp.divisor*=r.quotient;
		tmp.fractionCancellation();
		*this=tmp;
		return *this;
	}
	Rational& operator++() {
		if (checkDivisor()) return *this;
		quotient+=divisor;
		return *this;
	}
	Rational operator++(int) {
		Rational tmp(*this);
		operator++();
		return tmp;
	}
	Rational& operator--() {
		if (checkDivisor()) return *this;
		quotient-=divisor;
		return *this;
	}
	Rational operator--(int) {
		Rational tmp(*this);
		operator--();
		return tmp;
	}
	operator double() const {
		return double(quotient)/divisor;
	}

};
Rational operator+(const Rational &a, const Rational &b) {
	Rational tmp(a);
	tmp+=b;
	return tmp;
}
Rational operator-(const Rational &a, const Rational &b) {
	Rational tmp(a);
	tmp-=b;
	return tmp;
}
Rational operator/(const Rational &a, const Rational &b) {
	Rational tmp(a);
	tmp/=b;
	return tmp;
}
Rational operator*(const Rational &a, const Rational &b) {
	Rational tmp(a);
	tmp*=b;
	return tmp;
}
bool operator<(const Rational &a, const Rational &b) {
	if(a.quotient*b.divisor<b.quotient*a.divisor)
		return true;
	return false;		
}
bool operator>=(const Rational &a, const Rational &b) {
	return !(a<b);
}
bool operator==(const Rational &a, const Rational &b) {
	if(a.quotient*b.divisor==b.quotient*a.divisor)
		return true;
	return false;
}
bool operator!=(const Rational &a, const Rational &b) {
	return !(a==b);
}
bool operator<=(const Rational &a, const Rational &b) {
	return (a<b||a==b);
}
bool operator>(const Rational &a, const Rational &b) {
	return !(a<=b);
}

